// SPDX-License-Identifier: GPL-2.0-only
/*
 * Copyright (C) Huawei Technologies Co., Ltd. 2023. All rights reserved.
 * Description: Highmem ops
 * Author: Huawei OS Kernel Lab
 * Create: Mon Jul 31 15:34:01 2023
 */

#include <linux/pfn.h>
#include <linux/mman.h>
#include <lnxbase/iofast.h>

static int rsv_regions_num;
static struct lnxbase_iofast_region *rsv_regions;

int arch_highmem_page_mapped(struct page *pg)
{
	int i;
	unsigned long vaddr;

	if (pg == NULL)
		return 0;

	vaddr = (unsigned long)page_to_virt(pg);
	if (rsv_regions != NULL) {
		for (i = 0; i < rsv_regions_num; i++) {
			if ((vaddr >= rsv_regions[i].vstart) &&
			    (vaddr < (rsv_regions[i].vstart + rsv_regions[i].length))) {
				return 1;
			}
		}
	}

	return 0;
}

static int highmem_init_reserved_mem(void)
{
	rsv_regions_num = lnxbase_iofast_acquire_regions(&rsv_regions);
	return 0;
}
pure_initcall(highmem_init_reserved_mem);
